#define GVL_PROFILE 1
#include <gvl/support/profile.hpp>
#include <gvl/support/cstdint.hpp>

#include <iostream>

typedef uint32_t hash;

int const bits = 2;

hash h1(hash x)
{
#if 0
	hash a = (x << 17) | (x >> 15);
	hash b = (x << 7) | (x >> 25);
	x += 0x33a816ca;
	x ^= a | 64;
	x ^= b | 1;
	x *= x*2 + 1;
#endif


	x = (x+0x479ab41d) + (x<<8);
    x = (x^0xe4aa10ce) ^ (x>>5);
    x = (x+0x9942f0a6) - (x<<14);
    //x = (x^0x5aedd67d) ^ (x>>3);
    //x = (x+0x17bea992) + (x<<7);
	x *= x*2 + 1;
	
	/*
	x -= (x<<6);
    x ^= (x>>17);
    x -= (x<<9);
    x ^= (x<<4);
    x -= (x<<3);
    x ^= (x<<10);
    x ^= (x>>15);*/

	return x >> (32 - bits);
}

void hash_test()
{
	hash sum = 0;
	{
		GVL_PROF_TIMER("hash");
		
		for(int i = 0; i < 100000000; i += 1)
		{
			sum += h1(i);
		}
	}

	printf("%d\n", sum);
	gvl::present_profile(std::cout);
}